home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbimggblt.c,v < prev    next >
Encoding:
Text File  |  1990-02-15  |  12.7 KB  |  455 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.58.12;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  27. /***********************************************************
  28. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  29. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  30.  
  31.                         All Rights Reserved
  32.  
  33. Permission to use, copy, modify, and distribute this software and its 
  34. documentation for any purpose and without fee is hereby granted, 
  35. provided that the above copyright notice appear in all copies and that
  36. both that copyright notice and this permission notice appear in 
  37. supporting documentation, and that the names of Digital or MIT not be
  38. used in advertising or publicity pertaining to distribution of the
  39. software without specific, written prior permission.  
  40.  
  41. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  42. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  43. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  44. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  45. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  46. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  47. SOFTWARE.
  48.  
  49. ******************************************************************/
  50. /* $XConsortium: mfbimggblt.c,v 5.4 89/11/24 18:01:45 rws Exp $ */
  51. #include    "X.h"
  52. #include    "Xmd.h"
  53. #include    "Xproto.h"
  54. #include    "fontstruct.h"
  55. #include    "dixfontstr.h"
  56. #include    "gcstruct.h"
  57. #include    "windowstr.h"
  58. #include    "scrnintstr.h"
  59. #include    "pixmapstr.h"
  60. #include    "regionstr.h"
  61. #include    "mfb.h"
  62. #include    "maskbits.h"
  63.  
  64. extern void QueryGlyphExtents();
  65.  
  66. /*
  67.     we should eventually special-case fixed-width fonts for ImageText.
  68.  
  69.     this works for fonts with glyphs <= 32 bits wide.
  70.  
  71.     the clipping calculations are done for worst-case fonts.
  72. we make no assumptions about the heights, widths, or bearings
  73. of the glyphs.  if we knew that the glyphs are all the same height,
  74. we could clip the tops and bottoms per clipping box, rather
  75. than per character per clipping box.  if we knew that the glyphs'
  76. left and right bearings were wlle-behaved, we could clip a single
  77. character at the start, output until the last unclipped
  78. character, and then clip the last one.  this is all straightforward
  79. to determine based on max-bounds and min-bounds from the font.
  80.     there is some inefficiency introduced in the per-character
  81. clipping to make what's going on clearer.
  82.  
  83.     (it is possible, for example, for a font to be defined in which the
  84. next-to-last character in a font would be clipped out, but the last
  85. one wouldn't.  the code below deals with this.)
  86.  
  87.     Image text looks at the bits in the glyph and the fg and bg in the
  88. GC.  it paints a rectangle, as defined in the protocol dcoument,
  89. and the paints the characters.
  90.  
  91.    to avoid source proliferation, this file is compiled
  92. three times:
  93.     MFBIMAGEGLYPHBLT    OPEQ
  94.     mfbImageGlyphBltWhite    |=
  95.     mfbImageGlyphBltBlack    &=~
  96.  
  97.     the register allocations for startmask and endmask may not
  98. be the right thing.  are there two other deserving candidates?
  99. xoff, pdst, pglyph, and tmpSrc seem like the right things, though.
  100. */
  101.  
  102. void
  103. MFBIMAGEGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  104.     DrawablePtr pDrawable;
  105.     GC         *pGC;
  106.     int     x, y;
  107.     unsigned int nglyph;
  108.     CharInfoPtr *ppci;        /* array of character info */
  109.     unsigned char *pglyphBase;    /* start of array of glyphs */
  110. {
  111.     ExtentInfoRec info;    /* used by QueryGlyphExtents() */
  112.     BoxRec bbox;    /* string's bounding box */
  113.     xRectangle backrect;/* backing rectangle to paint.
  114.                in the general case, NOT necessarily
  115.                the same as the string's bounding box
  116.             */
  117.  
  118.     CharInfoPtr pci;
  119.     int xorg, yorg;    /* origin of drawable in bitmap */
  120.     int widthDst;    /* width of dst in longwords */
  121.  
  122.             /* these keep track of the character origin */
  123.     unsigned int *pdstBase;
  124.             /* points to longword with character origin */
  125.     int xchar;        /* xorigin of char (mod 32) */
  126.  
  127.             /* these are used for placing the glyph */
  128.     register int xoff;    /* x offset of left edge of glyph (mod 32) */
  129.     register unsigned int *pdst;
  130.             /* pointer to current longword in dst */
  131.  
  132.     int w;        /* width of glyph in bits */
  133.     int h;        /* height of glyph */
  134.     int widthGlyph;    /* width of glyph, in bytes */
  135.     register unsigned char *pglyph;
  136.             /* pointer to current row of glyph */
  137.  
  138.             /* used for putting down glyph */    
  139.     register unsigned int tmpSrc;
  140.             /* for getting bits from glyph */
  141.     register int startmask;
  142.     register int endmask;
  143.  
  144.     register int nFirst;/* bits of glyph in current longword */
  145.     void (* oldFillArea)();
  146.             /* we might temporarily usurp this
  147.                field in devPriv */
  148.  
  149.     if (!(pGC->planemask & 1))
  150.     return;
  151.  
  152.     xorg = pDrawable->x;
  153.     yorg = pDrawable->y;
  154.     if (pDrawable->type == DRAWABLE_WINDOW)
  155.     {
  156.     pdstBase = (unsigned int *)
  157.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  158.     widthDst = (int)
  159.          (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  160.     }
  161.     else
  162.     {
  163.     pdstBase = (unsigned int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  164.     widthDst = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  165.     }
  166.  
  167.     QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
  168.  
  169.     backrect.x = x;
  170.     backrect.y = y - pGC->font->pFI->fontAscent;
  171.     backrect.width = info.overallWidth;
  172.     backrect.height = pGC->font->pFI->fontAscent + 
  173.               pGC->font->pFI->fontDescent;
  174.  
  175.     x += xorg;
  176.     y += yorg;
  177.  
  178.     bbox.x1 = x + info.overallLeft;
  179.     bbox.x2 = x + info.overallRight;
  180.     bbox.y1 = y - info.overallAscent;
  181.     bbox.y2 = y + info.overallDescent;
  182.  
  183.     /* UNCLEAN CODE
  184.        we know the mfbPolyFillRect uses only three fields in
  185.        devPrivate[mfbGCPrivateIndex].ptr, two of which (the rotated
  186.        tile/stipple and the ropFillArea) are 
  187.        irrelevant for solid filling, so we just poke the FillArea
  188.        field.  the GC is now in an inconsistent state, but we'll fix
  189.        it as soon as PolyFillRect returns.  fortunately, the server
  190.        is single threaded.
  191.  
  192.     NOTE:
  193.        if you are not using the standard mfbFillRectangle code, you
  194.        need to poke any fields in the GC the rectangle stuff need
  195.        (probably alu, fgPixel, and fillStyle) and in devPrivate[mfbGCPrivateIndex].ptr
  196.        (probably rop or ropFillArea.)  You could just call ValidateGC,
  197.        but that is usually not a cheap thing to do.
  198.     */
  199.  
  200.     oldFillArea = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea;
  201.  
  202. /* pcc doesn't like this.  why?
  203.     ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = 
  204.             (pGC->bgPixel ? mfbSolidWhiteArea : mfbSolidBlackArea);
  205. */
  206.     if (pGC->bgPixel)
  207.         ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = mfbSolidWhiteArea;
  208.     else
  209.         ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = mfbSolidBlackArea;
  210.  
  211.     mfbPolyFillRect(pDrawable, pGC, 1, &backrect);
  212.     ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->FillArea = oldFillArea;
  213.  
  214.     /* the faint-hearted can open their eyes now */
  215.     switch ((*pGC->pScreen->RectIn)(
  216.           ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
  217.     {
  218.       case rgnOUT:
  219.     break;
  220.       case rgnIN:
  221.         pdstBase = pdstBase + (widthDst * y) + (x >> 5);
  222.         xchar = x & 0x1f;
  223.  
  224.         while(nglyph--)
  225.         {
  226.         pci = *ppci;
  227.         pglyph = pglyphBase + pci->byteOffset;
  228.         w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
  229.         h = pci->metrics.ascent + pci->metrics.descent;
  230.         widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
  231.  
  232.         /* start at top scanline of glyph */
  233.         pdst = pdstBase - (pci->metrics.ascent * widthDst);
  234.  
  235.         /* find correct word in scanline and x offset within it
  236.            for left edge of glyph
  237.         */
  238.         xoff = xchar + pci->metrics.leftSideBearing;
  239.         if (xoff > 31)
  240.         {
  241.             pdst++;
  242.             xoff &= 0x1f;
  243.         }
  244.         else if (xoff < 0)
  245.         {
  246.             xoff += 32;
  247.             pdst--;
  248.         }
  249.  
  250.         if ((xoff + w) <= 32)
  251.         {
  252.             /* glyph all in one longword */
  253.             maskpartialbits(xoff, w, startmask);
  254.             while (h--)
  255.             {
  256.             getleftbits(pglyph, w, tmpSrc);
  257.             *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
  258.             pglyph += widthGlyph;
  259.             pdst += widthDst;
  260.             }
  261.         }
  262.         else
  263.         {
  264.             /* glyph crosses longword boundary */
  265.             mask32bits(xoff, w, startmask, endmask);
  266.             nFirst = 32 - xoff;
  267.             while (h--)
  268.             {
  269.             getleftbits(pglyph, w, tmpSrc);
  270.             *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
  271.             *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
  272.             pglyph += widthGlyph;
  273.             pdst += widthDst;
  274.             }
  275.         } /* glyph crosses longwords boundary */
  276.  
  277.         /* update character origin */
  278.         x += pci->metrics.characterWidth;
  279.         xchar += pci->metrics.characterWidth;
  280.         if (xchar > 31)
  281.         {
  282.             xchar -= 32;
  283.             pdstBase++;
  284.         }
  285.         else if (xchar < 0)
  286.         {
  287.             xchar += 32;
  288.             pdstBase--;
  289.         }
  290.         ppci++;
  291.         } /* while nglyph-- */
  292.     break;
  293.       case rgnPART:
  294.       {
  295.     TEXTPOS *ppos;
  296.     int nbox;
  297.     BoxPtr pbox;
  298.     RegionPtr cclip;
  299.     int xpos;        /* x position of char origin */
  300.     int i;
  301.     BoxRec clip;
  302.     int leftEdge, rightEdge;
  303.     int topEdge, bottomEdge;
  304.     int glyphRow;        /* first row of glyph not wholly
  305.                    clipped out */
  306.     int glyphCol;        /* leftmost visible column of glyph */
  307.     int getWidth;        /* bits to get from glyph */
  308.  
  309.     if(!(ppos = (TEXTPOS *)ALLOCATE_LOCAL(nglyph * sizeof(TEXTPOS))))
  310.         return;
  311.  
  312.         pdstBase = pdstBase + (widthDst * y) + (x >> 5);
  313.         xpos = x;
  314.     xchar = xpos & 0x1f;
  315.  
  316.     for (i=0; i<nglyph; i++)
  317.     {
  318.         pci = ppci[i];
  319.  
  320.         ppos[i].xpos = xpos;
  321.         ppos[i].xchar = xchar;
  322.         ppos[i].leftEdge = xpos + pci->metrics.leftSideBearing;
  323.         ppos[i].rightEdge = xpos + pci->metrics.rightSideBearing;
  324.         ppos[i].topEdge = y - pci->metrics.ascent;
  325.         ppos[i].bottomEdge = y + pci->metrics.descent;
  326.         ppos[i].pdstBase = pdstBase;
  327.         ppos[i].widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
  328.  
  329.         xpos += pci->metrics.characterWidth;
  330.         xchar += pci->metrics.characterWidth;
  331.         if (xchar > 31)
  332.         {
  333.         xchar &= 0x1f;
  334.         pdstBase++;
  335.         }
  336.         else if (xchar < 0)
  337.         {
  338.         xchar += 32;
  339.         pdstBase--;
  340.         }
  341.     }
  342.  
  343.     cclip = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
  344.     pbox = REGION_RECTS(cclip);
  345.     nbox = REGION_NUM_RECTS(cclip);
  346.  
  347.     /* HACK ALERT
  348.        since we continue out of the loop below so often, it
  349.        is easier to increment pbox at the  top than at the end.
  350.        don't try this at home.
  351.     */
  352.     pbox--;
  353.     while(nbox--)
  354.     {
  355.         pbox++;
  356.         clip.x1 = max(bbox.x1, pbox->x1);
  357.         clip.y1 = max(bbox.y1, pbox->y1);
  358.         clip.x2 = min(bbox.x2, pbox->x2);
  359.         clip.y2 = min(bbox.y2, pbox->y2);
  360.         if ((clip.x2<=clip.x1) || (clip.y2<=clip.y1))
  361.         continue;
  362.  
  363.         for(i=0; i<nglyph; i++)
  364.         {
  365.         pci = ppci[i];
  366.         xchar = ppos[i].xchar;
  367.  
  368.         /* clip the left and right edges */
  369.         if (ppos[i].leftEdge < clip.x1)
  370.             leftEdge = clip.x1;
  371.         else
  372.             leftEdge = ppos[i].leftEdge;
  373.  
  374.         if (ppos[i].rightEdge > clip.x2)
  375.             rightEdge = clip.x2;
  376.         else
  377.             rightEdge = ppos[i].rightEdge;
  378.  
  379.         w = rightEdge - leftEdge;
  380.         if (w <= 0)
  381.             continue;
  382.  
  383.         /* clip the top and bottom edges */
  384.         if (ppos[i].topEdge < clip.y1)
  385.             topEdge = clip.y1;
  386.         else
  387.             topEdge = ppos[i].topEdge;
  388.  
  389.         if (ppos[i].bottomEdge > clip.y2)
  390.             bottomEdge = clip.y2;
  391.         else
  392.             bottomEdge = ppos[i].bottomEdge;
  393.  
  394.         h = bottomEdge - topEdge;
  395.         if (h <= 0)
  396.             continue;
  397.  
  398.         glyphRow = (topEdge - y) + pci->metrics.ascent;
  399.         widthGlyph = ppos[i].widthGlyph;
  400.         pglyph = pglyphBase + pci->byteOffset;
  401.         pglyph += (glyphRow * widthGlyph);
  402.  
  403.         pdst = ppos[i].pdstBase - ((y-topEdge) * widthDst);
  404.  
  405.         glyphCol = (leftEdge - ppos[i].xpos) -
  406.                (pci->metrics.leftSideBearing);
  407.         getWidth = w + glyphCol;
  408.         xoff = xchar + (leftEdge - ppos[i].xpos);
  409.         if (xoff > 31)
  410.         {
  411.             xoff &= 0x1f;
  412.             pdst++;
  413.         }
  414.         else if (xoff < 0)
  415.         {
  416.             xoff += 32;
  417.             pdst--;
  418.         }
  419.  
  420.         if ((xoff + w) <= 32)
  421.         {
  422.             maskpartialbits(xoff, w, startmask);
  423.             while (h--)
  424.             {
  425.             getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
  426.             *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
  427.             pglyph += widthGlyph;
  428.             pdst += widthDst;
  429.             }
  430.         }
  431.         else
  432.         {
  433.             mask32bits(xoff, w, startmask, endmask);
  434.             nFirst = 32 - xoff;
  435.             while (h--)
  436.             {
  437.             getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
  438.             *pdst OPEQ (SCRRIGHT(tmpSrc, xoff) & startmask);
  439.             *(pdst+1) OPEQ (SCRLEFT(tmpSrc, nFirst) & endmask);
  440.             pglyph += widthGlyph;
  441.             pdst += widthDst;
  442.             }
  443.         }
  444.         } /* for each glyph */
  445.     } /* while nbox-- */
  446.     DEALLOCATE_LOCAL(ppos);
  447.     break;
  448.       }
  449.       default:
  450.     break;
  451.     }
  452. }
  453.  
  454. @
  455.